import request from '@/utils/request'
// #ifdef H5
import { getSignLink } from '@/core/wechat'
// #endif

//发送短信
export function smsSend(data: any) {
    return request.post({ url: '/sms/send', data: data })
}

export function getConfig() {
    return request.get({ url: '/config' })
}

export function getPolicy(data: any) {
    return request.get({ url: '/policy', data: data })
}
/**
 * @param { Object } params
 * @return { Promise }
 * @description 支付方式列表
 */
export const apiPayPayWay = (data: any) => request.get({ url: '/order/pay/way/list', data })

/**
 * @param { Object } params
 * @return { Promise }
 * @description 订单支付
 */
export const apiPayPrePay = (params: any) =>
    request.post({ url: '/pay/wx/createOrder', data: params })
/**
 * @param { Object } params
 * @return { Promise }
 * @description h5订单支付
 */
export const apiH5PayPrePay = (params: any) =>
    request.post({ url: '/pay/h5/createOrder', data: params })

/**
 * @param { Object } params
 * @return { Promise }
 * @description 充值支付
 */
export const apichargeOrder = (params: any) =>
    request.post({ url: '/pay/wx/createRechargeOrder', data: params })

/**
 * @param { Object } params
 * @return { Promise }
 * @description 余额支付
 */
export const apiWalletPay = (params: any) =>
    request.post({ url: '/pay/balance/execute', data: params })

/**
 * @param { Object } params
 * @return { Promise }
 * @description 公众号登录
 */
export const apiOALogin = (params: any) => request.post({ url: 'login/oaLogin', data: params })

/**
 * @param { Object } params
 * @return { Promise }
 * @description 向微信请求code的链接
 */
export const apiCodeUrlGet = () =>
    request.get({
        url: 'login/codeUrl',
        data: {
            url: location.href,
            headers: { 1: 1 }
        }
    })

/**
 * @param { Object } params
 * @return { Promise }
 * @description 微信sdk配置
 */
export const apiJsConfig = () =>
    request.get({ url: '/wx/jssdk/valid', data: { url: getSignLink() } })

export function uploadImage(file: any, token?: string) {
    return request.uploadFile({
        url: '/upload/image',
        filePath: file,
        name: 'file',
        header: {
            token
        },
        fileType: 'image'
    })
}
